package com.crazybytex.modbus.beans;

import com.crazybytex.modbus.util.ByteStreamUtils;

import java.io.ByteArrayInputStream;

/**
 * @Author 程序员潇然 crazybytex.com
 * @Date 2022/8/3 17:47
 * @Description 电池负载电压和电流
 * 功能              地址              功能码                描述              单位               倍数
 * ------------------------------------------------------------------------------------------------
 *
 *负载电压          304A  (0d12362)  04 (只读)             负载电压              V                100
 *负载电流          304B  (0d12363)  04 (只读)             负载电流              A                100
 *
 *
 *
 **/
public class BatteryLoadVoltageAndCurrentResponse extends ModBusResponse{


    /**
     * 蓄电池电压
     */
    private int batteryLoadVoltage;



    /**
     * 蓄电池电流
     */
    private double batteryLoadCurrent;

    @Override
    public void parse(byte[] bytes) {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        try {
            batteryLoadVoltage = ByteStreamUtils.readShort(byteArrayInputStream)/100;

            batteryLoadCurrent = ByteStreamUtils.readShort(byteArrayInputStream)/100.00;

        }catch(Exception e){


        }

    }

    public int getBatteryLoadVoltage() {
        return batteryLoadVoltage;
    }

    public void setBatteryLoadVoltage(int batteryLoadVoltage) {
        this.batteryLoadVoltage = batteryLoadVoltage;
    }

    public double getBatteryLoadCurrent() {
        return batteryLoadCurrent;
    }

    public void setBatteryLoadCurrent(double batteryLoadCurrent) {
        this.batteryLoadCurrent = batteryLoadCurrent;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("BatteryLoadVoltageAndCurrentResponse{");
        sb.append("batteryLoadVoltage=").append(batteryLoadVoltage);
        sb.append(", batteryLoadCurrent=").append(batteryLoadCurrent);
        sb.append('}');
        return sb.toString();
    }
}
